
const domainName = getApp().globalData.domainName
const dataType = 'json'
const header = {'content-type':'application/x-www-form-urlencoded'}
const method = 'POST'
const responseType = 'text'





  // 设置选项
const set_opt=(that,e)=>{
    let index = e.currentTarget.id
    var row_id = that.data.list[index].chap_id
    var name = that.data.list[index].chap_name
    wx.showActionSheet({
      itemList: ['配置章-节','修改名称'],
      success: res => {
        // console.log('tapIndex',res.tapIndex)
        if(res.tapIndex==0){  // 类别
          wx.navigateTo({
            url:'/pages/sysConfig/config_textBook/section/section?id=' + row_id + '&name=' + name,
          })
        }else if(res.tapIndex==1){
          wx.showModal({
            content:name,
            editable: true,
            placeholderText: '请输入新名词',
            showCancel: true,
            title: '修改名称',
            success: res => {
              if(res.confirm){
                wx.request({
                  url: domainName + '/update_chap_name',
                  data: {
                    row_id:row_id,
                    new_name:res.content,
                  },
                  dataType: dataType,
                  enableCache: true,
                  enableHttp2: true,
                  enableQuic: true,
                  header: header,
                  method: method,
                  responseType: responseType,
                  timeout: 0,
                  success: res => {
                    wx.showToast({
                      title: '修改完成',
                      duration: 1500,
                      icon: 'success',
                    })
                    that.setData({
                      list:res.data.chap_list
                    })
                  },
                })
              }
            },
          })
        }
      },
    })

  }


    
  // 加载权限列表
const page_init=(that)=>{
    wx.request({
      url: domainName + '/load_chap_list',
      data: {},
      dataType: dataType,
      enableCache: true,
      enableHttp2: true,
      enableQuic: true,
      header: header,
      method: method,
      responseType: responseType,
      timeout: 0,
      success: res => {
        that.setData({
          show_mask:false,
          name:'',
          list:res.data.chap_list,
        })
      },
    })
  }



  module.exports={
    page_init:page_init,
    set_opt:set_opt,
  }